home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 119_01.zip / COMM5.C < prev    next >
Text File  |  1993-06-16  |  8KB  |  321 lines

  1. /* COMM5.C    Accumulated random Mince commands
  2.             Contributed to AUG by Mark of the Unicorn 07/20/81
  3.  
  4.     Copyrignt (C) 1981 Mark of the Unicorn
  5.  
  6. This  file contains the source for assorted commands that for one 
  7. reason or another (usually lack of code space) didn't make it into the
  8. official Mince version. 
  9.  
  10. Note to potential users: some of this code belongs in places other
  11. than in a COMMx.C file. (i.e. InsCmnd() belongs in Mince.) This means
  12. that you will have to move them there with CLIB, and move the one that
  13. is already there to another place. Alternately, put them at the end of
  14. the CBIND.C file and put it on the link line first, but only if you
  15. have added the extra globals to MINCE.GBL (as per Jason's
  16. instructions). Be careful about little things like this, it may mean
  17. the difference between code that works and code that does not. Also be
  18. especially wary of the use of tmp, cnt, tmark, spare and other
  19. 'trashable' globals. If you call other functions that use these you
  20. can get into trouble. It is probably always safer to redeclare these
  21. at the beginning (and lose a little stack) than to risk trashing at
  22. the hands of subsequent functions. Now that we can add globals, I
  23. would reccommend NOT using spare anymore. -[BAD, 09/22/81] */
  24.  
  25. #include "mince.gbl"
  26.  
  27. /* M-O */
  28.  
  29. MDropLine()        /* drop rest of this line vertically */
  30. {
  31.     if (BIsEnd() || IsNL()){
  32.         BInsert(NL);
  33.         BMove(-1);
  34.         return;
  35.         }
  36.     tmp=BGetCol();
  37.     BInsert(NL);
  38.     TIndent(tmp);
  39.     RNLSrch();
  40.     }
  41.  
  42. /* M-C-O */
  43. MCloseWhite()        /* replace following greyspace with a blank */
  44. {
  45.     MDelWhite();
  46.     while (!BisEnd() && IsNL()){
  47.         BDelete(1);
  48.         MDelWhite();
  49.         }
  50.     Binsert(' ');
  51.     arg=0;
  52.     }
  53.  
  54. /* The following are from Scott's Mince (MSCOTT.C) */
  55.  
  56. /* this M-T always swaps the previous two characters */
  57. MSwapChar()
  58. {
  59.     BMove(-1);
  60.     tmp=Buff();
  61.     BDelete(1);
  62.     BMove(-1);
  63.     BInsert(tmp);
  64.     BMove(1);
  65.     }
  66.  
  67. /* this doesn't split the line; I keep it on C-J */
  68. MIndNL()            /* Indent new line same as current */
  69. {
  70.     ToEndLine();
  71.     MIndRest();
  72.     }
  73.  
  74. /* This splits the line and indents; i keep it on M-C-J */
  75. MIndRest()            /* move rest of line to indented new line */
  76. {
  77.     tmark=BCreMrk();
  78.     cnt = GetInd();
  79.     BPntToMrk(tmark);
  80.     Binsert (NL);
  81.     TIndent (cnt);
  82.     BKillMrk(tmark);
  83.     }
  84.  
  85. /*for convenience */ 
  86. GetInd()                /* Get this line's indentation */
  87. {
  88.     int IsWhite();
  89.     
  90.     ToBegLine();
  91.     MovePast(&IsWhite,FORWARD);
  92.     return (BGetCol());
  93.     }
  94.     
  95. /* This opens a new line before the current one, and gives it the 
  96. same indentation; I keep it on M-O */
  97. MOpenIndLin()            /* open line at current indentation */
  98. {
  99.     tmp = GetInd();
  100.     ToBegLin();
  101.     BInsert (NL);
  102.     BMove(-1);
  103.     TIndent (tmp);
  104.     }
  105.     
  106.  
  107. /* C-X > */
  108. MIndntRgn()            /* indent the region */
  109. {
  110.     IndRgn (indentcol);
  111.     }
  112.  
  113. /* C-X < */
  114. MUndntRgn()            /* undent the region */
  115. {
  116.     IndRgn (-indentcol);
  117.     }
  118.  
  119. /* Internal to the above */
  120. IndRgn(amt)            /* add amt to the region's indentation */
  121. {
  122.     if (tmp = BIsAfterMrk (mark)) BSwapPnt (mark);
  123.     tmark = BCreMrk();
  124.     while (BIsBeforeMrk (mark)) {
  125.         cnt = GetInd();
  126.         MDelWhite();
  127.         TIndent (cnt + amt);
  128.         NLSrch();
  129.         }
  130.     BPntToMrk (tmark);
  131.     if (tmp) BSwapPnt (mark);
  132.     BKillMrk (tmark);
  133.     }
  134.  
  135. /* experimental: if you're at the beginning of a word, it moves to 
  136. the end of the previous word; else it moves to the beginning of 
  137. the next word. Currently on M-Z.  */
  138. MOthrTokn()            /* move to other non-token boundry */
  139. {
  140.     if (!BIsEnd() && !IsToken()) MoveTo (&IsToken, FORWARD);
  141.     else MoveTo (&IsToken, BACKWARD);
  142.     }
  143.  
  144. /* This special cases the end of the buffer, to always display "100%" there */
  145. ModeFlags()            /* Display the mode flags */
  146. {
  147.     int tloc, tlen;
  148.  
  149.     if (TKbRdy()) return;
  150.     TDisStr(TMaxRow()-2,stat_col," -");
  151.     tloc=BLocation(buffs[cbuff].bbuff);
  152.     tlen=BLength(buffs[cbuff].bbuff);
  153.     if (tloc==tlen) itot(100);
  154.     else if (tloc<325) itot((tloc*100)/tlen);
  155.     else if (tloc<3250) itot((tloc*10)/(tlen/10+1));
  156.     else itot (tloc/(tlen/100+1));
  157.     TPrntStr("%- ");
  158.     TPrntChar(BModp(buffs[cbuff].bbuff) ? '*' : ' ');
  159.     TPrntChar(DelCmnd(lfunct) ? '+' : ' ');
  160.     TCLEOL();
  161.     }
  162.  
  163. /* if you want M-<digit> to work for arguments, put this on M-0 through
  164. M-9, ... */
  165. MArgDgt()                /* meta-digit arguments */
  166. {
  167.     arg=(cmnd&0x7f)-'0';
  168.     NumArg(arg);
  169.     }
  170.  
  171. /* ... and put this on C-U. */
  172. MArg()                /* set up arguments */
  173. {
  174.     arg *= 4;
  175.     NumArg(0);
  176.     }
  177.     
  178. /* internal to the above. */
  179. NumArg(tmp)            /* collect numeric arguments */
  180.     int tmp;
  181. {
  182.     int tchar, eflag, cflag;
  183.  
  184.     cflag = FALSE;
  185.     eflag = ArgEcho(arg);
  186.     while ((tchar=(cmnd=TGetKb())&0x7F)>='0' && tchar<='9') {
  187.         tmp=tmp*10+tchar-'0';
  188.         cflag=TRUE;
  189.         eflag |= ArgEcho(tmp);
  190.         }
  191.     if (cflag) arg=tmp;
  192.     if (eflag) ClrEcho();
  193.     argp=TRUE;
  194.     (*functs[cmnd])();
  195.     }
  196.  
  197. /* auto-fill with the following properties: it never just inserts
  198. a NL (if you type spaces past the fill column it will just keep
  199. inserting them), so that it never wraps unless there is actually a
  200. word to wrap, and it only deletes one space before inserting the CR.
  201. Used with Fill Para below, it insures that sentences will ALWAYS end 
  202. with two spaces if you typed them that way (at the price of an 
  203. occasional trailing space on a line). */
  204. MFillChk()            /* check to see if we are beyond fillwidth
  205.                        and do something about it */
  206. {
  207.     tmark=BCreMrk();
  208.     tmp=FALSE;
  209.     while (TRUE) {
  210.         ToNotWhite(BACKWARD);
  211.         if (BGetCol() <= fillwidth) break;
  212.         tmp=TRUE;    
  213.         ToWhite(BACKWARD);
  214.         }
  215.     if(tmp) {
  216.         ToNotWhite(FORWARD);
  217.         BMove(-1);
  218.         BDelete(1);
  219.         BInsert(NL);
  220.         SIndent(indentcol);
  221.         }
  222.     BPntToMrk(tmark);
  223.     BInsert((cmnd==CR) ? NL : cmnd);
  224.     BKillMrk(tmark);
  225.     }
  226.  
  227. /* Fill paragraph to go with the above. When it breaks a line,
  228. it only deletes one space before inserting the Nl. */
  229. MFillPara()            /* fill paragraph*/
  230. {
  231.     int IsWhite();
  232.     
  233.     if (argp) fillwidth=arg;
  234.     arg=0;
  235.     tmark=BCreMrk();
  236.     BMove(-1);
  237.     MFPara();
  238.     BMove(-1);
  239.     if (BIsEnd() || IsGray()) {
  240.         BPntToMrk(tmark);
  241.         BKillMrk(tmark);
  242.         return;
  243.         }
  244.     BMove(1);
  245.     tmp=BCreMrk();
  246.     MBPara();
  247.     
  248.     While (BIsBefore(tmp)) {
  249.         ToWhite(FORWARD);
  250.         if (BGetCol() > fillwidth) {
  251.             ToWhite(BACKWARD);
  252.             BMove(-1);
  253.             BDelete(1);
  254.             BInsert(NL);
  255.             SIndent(indentcol);
  256.             ToWhite(FORWARD);
  257.             }
  258.         MovePast(&IsWhite,FORWARD);
  259.         if (IsNL() && BIsBefore(tmp)) {
  260.             BMove(1);
  261.             MDelWhite();
  262.             BMove(-1);
  263.             BDelete(1);
  264.             BInsert(' ');
  265.             }
  266.         }
  267.     
  268.     BPntToMrk(tmark);
  269.     BKillMrk(tmark);
  270.     BKillMrk(tmp);
  271.     }
  272.  
  273. /* End of stuff from MSCOTT.C */
  274.  
  275. /* Electric shift lock functions
  276. These consider ';' to begin a comment, and NL to end one (i.e. are designed
  277. for assembler or most Lisps). They uppercase everything as it is typed,
  278. unless it's in a comment. */
  279.  
  280. #define NORMAL 0
  281. #define COMMENT 1
  282.     int context;
  283.  
  284. /* this goes in mince */
  285. InsCmnd(lfunct)        /* tell if previous command was self-insert */
  286.     int(*lfunct)();
  287. {
  288.     int MInsert();
  289.     return (lfunct == &MInsert);
  290.     }
  291.  
  292. /* This goes in comm1 */
  293. MInsert()                /* self inserting commands */
  294. {
  295.     int pmark;
  296.     
  297.     if (!InsCmnd(lfunct)) {
  298.         context = NORMAL;
  299.         pmark = BCreMrk();
  300.         if (RNLSrch()) BMove(1);
  301.         while (BIsBeforeMrk(pmark)) {
  302.             if (Buff() == ';') {
  303.                 context = COMMENT;
  304.                 break;
  305.                 }
  306.             BMove(1);
  307.             }
  308.         BPntToMrk(pmark);
  309.         BKillMrk(pmark);
  310.         }
  311.     if (cmnd == ';') context = COMMENT;
  312.     else if (cmnd == CR) context = NORMAL;
  313.     if (context == NORMAL) BInsert(toupper(cmnd));
  314.     else BInsert(cmnd);
  315.     }
  316.  
  317. /* End of electric shift lock stuff */
  318.  
  319. /* END OF COMM5.C */    MSCOTT.C */
  320.  
  321. /